/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * TelaPrincipal.java
 *
 * Created on 29/10/2011, 00:38:29
 */
package visao;

import java.lang.String;
import javax.swing.JOptionPane;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;

/**
 *
 * @author Heitor
 */
public class TelaPrincipal extends javax.swing.JFrame {

    DefaultMutableTreeNode raiz = new DefaultMutableTreeNode("/");

    /** Creates new form TelaPrincipal */
    public TelaPrincipal() {
        initComponents();
        limparTree();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jToolBar1 = new javax.swing.JToolBar();
        jbHDToPendrive = new javax.swing.JButton();
        jbExcluir = new javax.swing.JButton();
        jbPendriveToHD = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTree1 = new javax.swing.JTree();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();
        jmSobre = new javax.swing.JMenu();
        jmiSobre = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setResizable(false);

        jToolBar1.setFloatable(false);
        jToolBar1.setRollover(true);

        jbHDToPendrive.setIcon(new javax.swing.ImageIcon("/home/heitor/NetBeansProjects/trunk/Ninef/src/icones/hd to pen.png")); // NOI18N
        jbHDToPendrive.setText("Copiar do HD para Pendrive");
        jbHDToPendrive.setEnabled(false);
        jbHDToPendrive.setFocusable(false);
        jbHDToPendrive.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jbHDToPendrive.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jbHDToPendrive.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbHDToPendriveActionPerformed(evt);
            }
        });
        jToolBar1.add(jbHDToPendrive);

        jbExcluir.setIcon(new javax.swing.ImageIcon("/home/heitor/NetBeansProjects/trunk/Ninef/src/icones/delete-64.png")); // NOI18N
        jbExcluir.setText("Formatar");
        jbExcluir.setEnabled(false);
        jbExcluir.setFocusable(false);
        jbExcluir.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jbExcluir.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jbExcluir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbExcluirActionPerformed(evt);
            }
        });
        jToolBar1.add(jbExcluir);

        jbPendriveToHD.setIcon(new javax.swing.ImageIcon("/home/heitor/NetBeansProjects/trunk/Ninef/src/icones/pen to hd.png")); // NOI18N
        jbPendriveToHD.setText("Copiar do Pendrive para HD");
        jbPendriveToHD.setEnabled(false);
        jbPendriveToHD.setFocusable(false);
        jbPendriveToHD.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jbPendriveToHD.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jbPendriveToHD.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbPendriveToHDActionPerformed(evt);
            }
        });
        jToolBar1.add(jbPendriveToHD);

        jScrollPane1.setViewportView(jTree1);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, 507, Short.MAX_VALUE)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(12, 12, 12)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 483, Short.MAX_VALUE)
                .addGap(12, 12, 12))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 521, Short.MAX_VALUE)
                .addContainerGap())
        );

        jMenu1.setText("Arquivo");

        jMenuItem1.setText("Carregar");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem1);

        jMenuBar1.add(jMenu1);

        jmSobre.setText("Sobre");

        jmiSobre.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.CTRL_MASK));
        jmiSobre.setText("Sobre");
        jmSobre.add(jmiSobre);

        jMenuBar1.add(jmSobre);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void jbHDToPendriveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbHDToPendriveActionPerformed
    /*aqui podemos 
     *  1 - tomar a entrada como uma string sendo o caminho do arquivo
     *  2 - abrir uma área de seleção de arquivo de origem 
     * e como destino tbm..?!
     */
    String origem = null;
    String destino = null;
    //JOptionPane.showInputDialog(rootPane, evt).
    origem = JOptionPane.showInputDialog(rootPane, "Local do arquivo: (exemplo: /home/usuario/fofuxo.doc)", " Origem no HD", 0);
    if (origem != null) {
        destino = JOptionPane.showInputDialog(rootPane, "O pendrive já é o distino. "
                + "\nEntre com uma pasta ou somente / para enviar o arquivo para o pendrive(exemplo: /fofuxinho)", " Destino do Arquivo no Pendrive", 0);
    }

    //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    //Agora chamamos a função de copiar com os parametros origem e destino

    try {
        if ((origem != null) && (destino != null)) {
            System.out.println("entro ");

        }
    } catch (Exception e) {
        JOptionPane.showMessageDialog(rootPane, e);
    }






}//GEN-LAST:event_jbHDToPendriveActionPerformed

private void jbPendriveToHDActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbPendriveToHDActionPerformed

    String origem = null;
    String destino = null;
    origem = JOptionPane.showInputDialog(rootPane, "Local do arquivo: (exemplo: /fofuxo.doc)", " Origem do Arquivo no Pendrive", 0);
    if (origem != null) {
        destino = JOptionPane.showInputDialog(rootPane, "Destino: (exemplo: /home/usuario)", " Destino no HD", 0);
    }


    try {
        if ((origem != null) && (destino != null)) {
            System.out.println("entro2 ");

        }
    } catch (Exception e) {
        JOptionPane.showMessageDialog(rootPane, e);
    }

}//GEN-LAST:event_jbPendriveToHDActionPerformed

private void jbExcluirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbExcluirActionPerformed
    String[] vetor = new String[10];
    for (int i = 0; i < 10; i++) {
        vetor[i] = Integer.toString(i);
    }
    criaCamninho(vetor);
}//GEN-LAST:event_jbExcluirActionPerformed

private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
    //Carrega o pendrive. começa o programa...



    jbHDToPendrive.setEnabled(true);
    jbPendriveToHD.setEnabled(true);
    jbExcluir.setEnabled(true);
}//GEN-LAST:event_jMenuItem1ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(TelaPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(TelaPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(TelaPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(TelaPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new TelaPrincipal().setVisible(true);
            }
        });
    }

    public void addNaJTree(String nomeNodo) {
        raiz.add(new DefaultMutableTreeNode(nomeNodo));
        jTree1 = new JTree(raiz);
        jScrollPane1.setViewportView(jTree1);
    }

    public void criaCamninho(String[] nomeNodo) {
        
            DefaultMutableTreeNode aux = new DefaultMutableTreeNode(nomeNodo[nomeNodo.length - 1]);
            DefaultMutableTreeNode aux2;
            for (int i = nomeNodo.length - 2; i > 0; i--) {
                aux2 = new DefaultMutableTreeNode(nomeNodo[i]);
                aux2.add(aux);
                aux = aux2;
            }
            raiz.add(aux);
            jTree1 = new JTree(raiz);
            jScrollPane1.setViewportView(jTree1);
       
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JToolBar jToolBar1;
    private javax.swing.JTree jTree1;
    private javax.swing.JButton jbExcluir;
    private javax.swing.JButton jbHDToPendrive;
    private javax.swing.JButton jbPendriveToHD;
    private javax.swing.JMenu jmSobre;
    private javax.swing.JMenuItem jmiSobre;
    // End of variables declaration//GEN-END:variables

    private void limparTree() {
        jScrollPane1.setViewportView(null);
    }


//    private String[] novoCaminho(String[] nomeNodo) {
//        String[] novo;
//        
//        
//        
//        
//        
//        return
//    }
}
